<template>
  <el-dropdown trigger="click" @command="handleCommand">
    <span class="el-dropdown-link outline-none">
      <SvgIcon
        icon-name="ant-design:global-outlined"
        custom-class="h-[28px] w-[28px] ml-[10px] cursor-pointer"
      ></SvgIcon>
    </span>

    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          v-for="item in langOptions"
          :key="item.value"
          :command="item.value"
          :disabled="lang === item.value"
        >
          {{ item.label }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts" name="SwitchLang">
import { useAppStore } from "@/store"

const appStore = useAppStore()
const { lang } = storeToRefs(appStore)
const langOptions = [
  {
    label: "中文",
    value: "zh-cn"
  },
  {
    label: "English",
    value: "en"
  }
]

const handleCommand = (value: string) => {
  appStore.setLang(value)
}
</script>
